package com.kxmall.web.controller.vehicle;

import cn.dev33.satoken.annotation.SaIgnore;
import com.kxmall.common.core.controller.BaseAppController;
import com.kxmall.common.core.domain.R;
import com.kxmall.common.utils.PageData;
import com.kxmall.vehicle.domain.vo.KxUserGoodsOrderVo;
import com.kxmall.vehicle.domain.vo.KxVehicleBoxGoodsOrderVo;
import com.kxmall.vehicle.domain.vo.KxVehicleVo;
import com.kxmall.web.controller.vehicle.service.IKxAppVehicleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 餐车管理
 */
@Api(tags = "餐车管理")
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/vehicle/app")
public class KxAppVehicleController extends BaseAppController {

    private final IKxAppVehicleService iKxAppVehicleService;

    /**
     * 获取餐车柜子里的商品信息
     */
    @SaIgnore
    @GetMapping("/getVehicleBoxGoodsInfo")
    @ApiOperation(value = "/vehicle/app/getVehicleBoxGoodsInfo - 获取餐车柜子里的商品信息", httpMethod = "GET")
    public R<KxVehicleVo> getVehicleBoxGoodsInfo(@NotNull(message = "餐车动力单元编号不能为空") String vehicleNo) {
        return R.ok(iKxAppVehicleService.getVehicleBoxGoodsInfo(vehicleNo));
    }

    /**
     * 创建餐车柜子的商品订单
     */
    @GetMapping("/createVehicleBoxGoodsOrder")
    @ApiOperation(value = "/vehicle/app/createVehicleBoxGoodsOrder - 创建餐车柜子的商品订单", httpMethod = "GET")
    public PageData createVehicleBoxGoodsOrder(@NotNull(message = "餐车动力单元编号不能为空") String vehicleNo, @NotNull(message = "车厢索引不能为空") Integer boxIndex) {
        Long userId = getAppLoginUser().getUserId();
        return iKxAppVehicleService.createVehicleBoxGoodsOrder(userId, vehicleNo, boxIndex);
    }

    /**
     * 获取用户的商品订单列表
     */
    @GetMapping("/getUserGoodsOrderList")
    @ApiOperation(value = "/vehicle/app/getUserGoodsOrderList - 获取用户的商品订单列表", httpMethod = "GET")
    public R<List<KxUserGoodsOrderVo>> getUserGoodsOrderList() {
        Long userId = getAppLoginUser().getUserId();
        return R.ok(iKxAppVehicleService.getUserGoodsOrderList(userId));
    }
}
